/*    */ package com.zimbra.cs.service.mail;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.MailConstants;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.Message;
/*    */ import com.zimbra.cs.mailbox.OperationContext;
/*    */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.ArrayList;
/*    */ import java.util.HashMap;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import java.util.Map.Entry;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class GetMsgMetadata
/*    */   extends MailDocumentHandler
/*    */ {
/*    */   static final int SUMMARY_FIELDS = 4195127;
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 41 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 42 */     Mailbox mbox = getRequestedMailbox(zsc);
/* 43 */     OperationContext octxt = getOperationContext(zsc, context);
/* 44 */     ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
/*    */     
/* 46 */     String ids = request.getElement("m").getAttribute("ids");
/* 47 */     ArrayList<Integer> local = new ArrayList();
/* 48 */     HashMap<String, StringBuilder> remote = new HashMap();
/* 49 */     ItemAction.partitionItems(zsc, ids, local, remote);
/*    */     
/* 51 */     Element response = zsc.createElement(MailConstants.GET_MSG_METADATA_RESPONSE);
/*    */     
/* 53 */     if (remote.size() > 0) {
/* 54 */       List<Element> responses = proxyRemote(request, remote, context);
/* 55 */       for (Element e : responses) {
/* 56 */         response.addElement(e);
/*    */       }
/*    */     }
/*    */     
/* 60 */     if (local.size() > 0) {
/* 61 */       List<Message> msgs = GetMsg.getMsgs(octxt, mbox, local, false);
/* 62 */       for (Message msg : msgs) {
/* 63 */         if (msg != null) {
/* 64 */           ToXML.encodeMessageSummary(response, ifmt, octxt, msg, null, 4195127);
/*    */         }
/*    */       }
/*    */     }
/*    */     
/* 69 */     return response;
/*    */   }
/*    */   
/*    */   List<Element> proxyRemote(Element request, Map<String, StringBuilder> remote, Map<String, Object> context) throws ServiceException
/*    */   {
/* 74 */     List<Element> responses = new ArrayList();
/*    */     
/* 76 */     Element eMsg = request.getElement("m");
/* 77 */     for (Map.Entry<String, StringBuilder> entry : remote.entrySet()) {
/* 78 */       eMsg.addAttribute("ids", ((StringBuilder)entry.getValue()).toString());
/*    */       
/* 80 */       Element response = proxyRequest(request, context, (String)entry.getKey());
/* 81 */       for (Element e : response.listElements()) {
/* 82 */         responses.add(e.detach());
/*    */       }
/*    */     }
/*    */     
/* 86 */     return responses;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/GetMsgMetadata.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */